package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.*;

import static java.nio.file.Files.readAllBytes;
import static java.nio.file.Paths.get;

/**
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-09-12 10:22
 */
public class T13 {

    public static void main(String[] args) throws IOException {
        String str1 = "Hi, hello world !";
        String[] split = str1.split(" ");
        int len  = split.length;
//        System.out.print(" ");
        for (int i = 0; i < len; i++) {
            System.out.print(split[len-i-1] + " ");
        }

        TreeMap<Integer,Integer> map = new TreeMap<>(((o1, o2) -> o1.compareTo(o2)));


        //获取当前日期
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime.getYear() + "年" + dateTime.getMonth().getValue()+"月" + dateTime.getDayOfMonth()+"日 "+dateTime.getHour()+":"+dateTime.getMinute()+":"+dateTime.getMinute());

        //txt文件读取函数
        //readFile("E:\\Gitee\\programming_exercises\\src\\main\\java\\test\\Solution.java");

        //读取properties文件
        readProperities("test");
    }


    /**
     * JDK8中读取文件的几种方式
     * http://justcode.ikeepstudying.com/2017/05/java-java8%E6%B5%81%E9%80%90%E8%A1%8C%E8%AF%BB%E5%8F%96%E6%96%87%E4%BB%B6/
     * @param url
     * @throws IOException
     */
    public static void readFile(String url) throws IOException {
        //方法1
        Path path = get(url);
        Files.lines(path, StandardCharsets.UTF_8).forEach(System.out::println);

        //方法2
        System.out.println(new String(readAllBytes(get(url))));

        //方法3 BufferedReader + Stream
        BufferedReader br = new BufferedReader(new FileReader(url));
        String line;
        while ((line = br.readLine()) != null){
            System.out.println(line);
        }

        HashMap<Integer,Integer> map = new HashMap<>();

        for (Integer integer : map.keySet()) {
            System.out.println(map.get(integer));
        }


    }

    public static void readProperities(String name){
        //获取资源包
        ResourceBundle rb = ResourceBundle.getBundle(name.trim());

        Enumeration<String> keys = rb.getKeys();

        //遍历
        while (keys.hasMoreElements()){
            String key = keys.nextElement();
            String value = rb.getString(key);
            System.out.println(value);
        }
    }


}
